package cn.edu.ahu.aircondition.monitor.realtime.manage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class EmailManage {

    private final String setFrom;
    private final JavaMailSender mailSender;

    @Autowired
    public EmailManage(@Value("${spring.mail.username}")String setFrom, JavaMailSender mailSender) {
        this.setFrom = setFrom;
        this.mailSender = mailSender;
    }

    void sendSimpleMail(String sendTo, String title, String content) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(setFrom);
        message.setTo(sendTo);
        message.setSubject(title);
        message.setText(content);
        mailSender.send(message);
    }
}
